package cn.gwm.flink.streaming.dwd.consumer;

import cn.gwm.flink.streaming.constant.VehicleType;
import cn.gwm.flink.streaming.dwd.check.VehicleConsumer;
import cn.gwm.utils.ConfigLoader;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @ClassName ES11Consumer
 * @Description
 * @Author LiangGuang
 * @Date 2023/05/18 11:02
 */
@Data
@Accessors(chain = true)
public class ES11Consumer extends VehicleConsumer {
    public ES11Consumer() {
        this.topic = ConfigLoader.get("kafka.clean.topic.ods.es11");
        this.groupId = "consumer-dwd-es11";
        this.customType = VehicleType.POWER_TYPE_EV;
        this.mileage = "VehTotDistance";
        this.vehicleType = VehicleType.ES11;
        this.uidSuffix = VehicleType.ES11;
    }

    public ES11Consumer(String uidSuffix) {
        this.topic = ConfigLoader.get("kafka.clean.topic.ods.es11");
        this.groupId = "consumer-dwd-es11";
        this.customType = VehicleType.POWER_TYPE_EV;
        this.mileage = "VehTotDistance";
        this.vehicleType = VehicleType.ES11;
        this.uidSuffix = uidSuffix;
    }

    @Override
    public void importanKeySupplement(JSONObject source) {
        // 对单个字段 处理一下  此时还是原始字段
        if (source.containsKey("BMS_InnerSOC") && !StrUtil.DASHED.equals(source.getStr("BMS_InnerSOC"))) {
            double bmsInnerSOC = source.getDouble("BMS_InnerSOC") / 10;
            source.set("BMS_InnerSOC", bmsInnerSOC);
        }
        if (source.containsKey("BMS_InnerSOCmax") && !StrUtil.DASHED.equals(source.getStr("BMS_InnerSOCmax"))) {
            double bmsInnerSOC = source.getDouble("BMS_InnerSOCmax") / 10;
            source.set("BMS_InnerSOCmax", bmsInnerSOC);
        }
        if (source.containsKey("BMS_InnerSOCmin") && !StrUtil.DASHED.equals(source.getStr("BMS_InnerSOCmin"))) {
            double bmsInnerSOC = source.getDouble("BMS_InnerSOCmin") / 10;
            source.set("BMS_InnerSOCmin", bmsInnerSOC);
        }
        super.importanKeySupplement(source);
    }

}
